﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media;
namespace DataLayer
{
    public class ImageContent : NodeContent
    {
        //int resourceID;

        //public int ResourceID
        //{
        //    get { return resourceID; }
        //    set { resourceID = value; }
        //}


        string imagePath;

        public string ImagePath
        {
            get { return imagePath; }
            set { imagePath = value; }
        }
        ImageSource content;

        public ImageSource Content
        {
            get { return content; }
            set { content = value; }
        }

       
        public ImageContent(string _imagePath)
        {
            if (System.IO.File.Exists(_imagePath))
            {
                this.imagePath = _imagePath;
                try
                {
                    this.content = new ImageSourceConverter().ConvertFromString(_imagePath) as ImageSource;
                }
                catch
                { 
                    
                }

            }
        }

        
         public string GetRelativePath()
        {
            int rsIndex = this.imagePath.IndexOf(@"resource/");
            int iIndex = this.imagePath.IndexOf(@"\Images/");
            string rs = "";
            if (rsIndex > 0)
            {
                rs = imagePath.Substring(rsIndex);
            }
            if (iIndex > 0)
            {
                rs = imagePath.Substring(iIndex+1);
            }
            return rs;
        }
    }
}
